package com.mianyang.zhangsan.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mianyang.zhangsan.common.constant.SecConstant;
import com.mianyang.zhangsan.common.util.OperationManHelper;
import com.mianyang.zhangsan.common.util.StringUtils;
import com.mianyang.zhangsan.model.dto.SecPaperDto;
import com.mianyang.zhangsan.model.entity.SecTemplate;
import com.mianyang.zhangsan.plugin.oss.MinioService;
import com.mianyang.zhangsan.service.SecTemplateService;
import com.mianyang.zhangsan.mapper.SecTemplateMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

/**
* @author jiangjr
*/
@Service
public class SecTemplateServiceImpl extends ServiceImpl<SecTemplateMapper, SecTemplate>
    implements SecTemplateService{
    @Autowired
    private MinioService minioService;

    @Override
    public Page<SecTemplate> selectTemplateByPage(SecTemplate template, Integer current, Integer pageSize) {
        QueryWrapper<SecTemplate> wrapper = new QueryWrapper<>();
        if (StringUtils.isNotEmpty(template.getTemplateName())) {
            wrapper.like("template_name", template.getTemplateName());
        }
        if (StringUtils.isNotEmpty(template.getAccountName())) {
            wrapper.like("account_name", template.getAccountName());
        }
        return page(new Page<>(current, pageSize), wrapper);
    }

    @Override
    public String selectTemplatePath(Long templateId) {
        SecTemplate template = getById(templateId);
        return template.getTemplatePath();
    }

    @Override
    public void insertTemplate(SecTemplate template) {
        // todo redis config template path
        if (template != null) {
            template.setTemplatePath(SecConstant.BASE_EXPORT_TEMPLATE);
            template.setAccountId(OperationManHelper.getAccountId());
            template.setAccountName(OperationManHelper.getAccountName());
            save(template);
        }
    }
}




